<template>
  <div>
    <my-form-drawer
      :title="`设置过期时间`"
      :width="500"
      :visible="visible"
      @ok="edit"
      @cancel="onClose"
    >
      <a-form-model ref="form" :model="form" :rules="rules">
        <a-form-model-item label="过期时间设置（分钟）" prop="configValue">
          <a-input-number v-model="form.configValue" :formatter="limit" :min="1" />
        </a-form-model-item>
      </a-form-model>
    </my-form-drawer>
  </div>
</template>

<script>
import moment from "moment";
import MyFormDrawer from "@/components/drawer/MyFormDrawer";
import { limitNumber } from "@/utils/common";
import { getExpire, setConfig } from "@/services/user"

export default {
  name: "userExpire",
  components: { MyFormDrawer },
  data() {
    return {
      form: {
        id:0,
        configValue: 30,
      },
      rules: {
        expire:[{ required: true, message: '请输入时间', trigger: 'blur' },]
      },
      visible: false
    };
  },
  computed: {},
  created() {

  },
  mounted () {
  },
  methods: {
    moment,
    limit(value) {
      return limitNumber(value);
    },
    changeForm(state) {
      this.visible = state;
      this.getExpire();
    },
    onClose() {
      this.visible = false;
      this.$refs["form"].clearValidate();
    },
    getExpire(){
      getExpire().then((res) => {
        console.log(res);
        if(res.data.code === 0){
          this.form.id = res.data.data.id;
          this.form.configValue = res.data.data.configValue;
          this.form.configKey = res.data.data.configKey;
        }
      })
    },
    edit(){
      let  editConfig = {
          id: this.form.id,
          configValue: this.form.configValue,
          configKey: this.form.configKey
      }
      setConfig(editConfig).then(res => {
        if(res.data.code == 0){
          this.$message.success('操作成功');
          this.onClose();
        }
      })
    }
  }
};
</script>

<style lang="less" scoped></style>
